package org.geek.webgui;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Toast;

public class webgui extends Activity {
	
	WebView browser;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
                
        browser = (WebView)findViewById(R.id.webkit);
        
        browser.getSettings().setJavaScriptEnabled(true);
        
        //browser.setWebViewClient(new CallBack());
        
        DroidHandler h = new DroidHandler(browser);
        
        browser.addJavascriptInterface(h, "host");
        
        browser.loadUrl("file:///android_asset/main.htm");
        
    }
    
    public class DroidHandler{
    	
    	private WebView webapp;
    	
    	public DroidHandler(WebView wv){
    		this.webapp = wv;
    	}
    	
    	public void displayToast(String message){
    		Toast.makeText(this.webapp.getContext(), message, Toast.LENGTH_SHORT).show();
    	}
    	
    	public String getInfo(){
    		return "Yeah Baby Yeah !";
    	}
    	
    	
    	public void callTest(){
    		this.webapp.loadUrl("javascript:Test()");
    	}
    	
    	public void callTestBis(String params){
    		this.webapp.loadUrl("javascript:TestBis('"+params+"')");
    	}    	
    	
    	
    	public void callJS(String params){
    		this.webapp.loadUrl("javascript:CalledByAndroid("+params+");");
    	}
    	
    }
    
    
    public  void displayToast(String message){
    	Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }
    
    /*
    private class CallBack extends WebViewClient{
    	@Override public boolean shouldOverrideUrlLoading(WebView view, String url){
    		
    		//browser.loadUrl("file:///android_asset/test.htm");
    		
    		//Log.i("shouldOverrideUrlLoading", url);
    		
    		displayToast(url);
    		
    		return true;
    	}
    }
    */
    
}